﻿using Client.Components.Icons;
using Client.Components.ToolbarControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Client.Components
{
    /// <summary>
    /// Interaction logic for IconImage.xaml
    /// </summary>
    public partial class IconImage : UserControl
    {
        public IconImage()
        {
            InitializeComponent();
        }

		#region Icon

		public static readonly DependencyProperty IconProperty = DependencyProperty.Register
		(
			name: "Icon",
			propertyType: typeof(IconEnum),
			ownerType: typeof(IconImage),
			validateValueCallback: null, // new ValidateValueCallback((toValidate) => { return true; }),
			typeMetadata: new PropertyMetadata
			(
				defaultValue: IconEnum.NONE,
				propertyChangedCallback: onIcon_PropertyChangedCallback,
				coerceValueCallback: null
			)
		);

		public IconEnum Icon
		{
			get { return (IconEnum)GetValue(IconProperty); }
			set { SetValue(IconProperty, value); }
		}

		public static void onIcon_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
		{
			if (d is IconImage target && e.NewValue != null)
			{
				IconEnum icon = (IconEnum)Enum.Parse(typeof(IconEnum), e.NewValue.ToString());
                string uriStr = IconEnumUtils.GetIconResourcePath(icon);

                BitmapImage image = new BitmapImage();
                image.BeginInit();
                image.UriSource = new Uri(uriStr);
                image.EndInit();
                
				target.img0.Source = image;
            }
		}

        #endregion

        #region [DP] ImageWidth

        /// <summary>
        /// ImageWidth
        /// </summary>
        public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register
        (
            name: "ImageWidth",
            propertyType: typeof(double),
            ownerType: typeof(IconImage),
            validateValueCallback: null, // new ValidateValueCallback((toValidate) => { return true; }),
            typeMetadata: new PropertyMetadata
            (
                defaultValue: 32d,
                propertyChangedCallback: null,
                coerceValueCallback: null
            )
        );

        /// <summary>
        /// ImageWidth
        /// </summary>
        public double ImageWidth
        {
            get { return (double)GetValue(ImageWidthProperty); }
            set { SetValue(ImageWidthProperty, value); }
        }

        #endregion

        #region [DP] ImageHeight

        /// <summary>
        /// ImageHeight
        /// </summary>
        public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register
        (
            name: "ImageHeight",
            propertyType: typeof(double),
            ownerType: typeof(IconImage),
            validateValueCallback: null, // new ValidateValueCallback((toValidate) => { return true; }),
            typeMetadata: new PropertyMetadata
            (
                defaultValue: 32d,
                propertyChangedCallback: null,
                coerceValueCallback: null
            )
        );

        /// <summary>
        /// ImageHeight
        /// </summary>
        public double ImageHeight
        {
            get { return (double)GetValue(ImageHeightProperty); }
            set { SetValue(ImageHeightProperty, value); }
        }

        #endregion
    }
}
